import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { ImagesConst } from "../../../resource/ImagesConst";
import { TilePanel } from "../../equipment/TilePanel";
import { PetExploreAutoResultRenderer } from "./PetExploreAutoResultRenderer";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { ObjCreate } from "../../common/ObjCreate";
import { SPetExploreResult } from "../../../../../Message/Public/SPetExploreResult";
import { Cache } from "../../../cache/Cache";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GameController } from "../../../mvc/GameController";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class PetExploreAutoResultWindow
    
    export  class PetExploreAutoResultWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null, arg2: Function=null)
        {
            super(arg1);
            this.setSize(355, 355);
            this.titleHeight = 28;
            this.title = Language.getString(54642);
            this._hideCallBackFun = arg2;
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this.addChild(new GImageBitmap(ImagesConst.PetExploreAutoBg, 17, 39));
            this._listPanel = new TilePanel();
            this._listPanel.setSize(310, 270);
            this._listPanel.columnWidth = 290;
            this._listPanel.rowHeight = 90;
            this._listPanel.setStyle("cellRenderer", PetExploreAutoResultRenderer);
            this._listPanel.move(17, 45);
            this.addChild(this._listPanel);
            this._listPanel.dataProvider = new DataProvider([0, 0, 0, 0, 0, 0, 0, 0, 0]);
            this._stopBtn = ObjCreate.createGButton(Language.getString(54643), 100, 315, 70, 28, this);
            this._stopBtn.toolTipData = Language.getString(54644);
            this._stopBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onStopBtnClickHandler);
            this._hideBtn = ObjCreate.createGButton(Language.getString(54648), 185, 315, 70, 28, this);
            this._hideBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onHideBtnClickHandler);
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            super.createDisposedChildrenImpl();
            if (closeBtn) 
            {
                closeBtn.visible = false;
            }
            return;
        }

        public updateByResultArray(arg1: Array<any>): void
        {
            var loc2=0;
            var loc1=this._listPanel.verticalScrollPosition;
            var loc3=[];
            var loc4;
            (loc4 = new SPetExploreResult()).autoExplore = true;
            loc4.currentLevel = Cache.instance.petExplore.petExploreInfo.currentLevel;
            loc4.cards = [];
            loc4.rewards = [];
            (loc3 = loc3.concat(arg1)).push(loc4);
            loc2 = this._listPanel.maxVerticalScrollPosition;
            this._listPanel.dataProvider = new DataProvider(loc3);
            if (loc1 == 0 || loc1 == loc2) 
            {
                this._listPanel.verticalScrollPosition = this._listPanel.maxVerticalScrollPosition;
            }
            return;
        }

        /* internal  */onStopBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetExploreAutoStop, this.onStop));
            return;
        }

        /* internal  */onHideBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            GameController.petExplore.view.hide();
            return;
        }

        /* internal  */onStop(): void
        {
            this._stopBtn.enabled = false;
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            _isFirstCenter = true;
            super.show();
            this._stopBtn.enabled = true;
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            if (this._hideCallBackFun != null) 
            {
                this._hideCallBackFun();
            }
            return;
        }

        /* internal */ /* var */_listPanel: TilePanel;

        /* internal */ /* var */_stopBtn: GButton;

        /* internal */ /* var */_hideBtn: GButton;

        /* internal */ /* var */_hideCallBackFun: Function;
    }
